package config

import (
	"github.com/go-redis/redis/v8"
	"go-micro.dev/v4"
)

var (
	KV           *redis.Client
	Conf         = &Config{}
	MicroService micro.Service
	configFile   = ""
	EtcdAddr     = ""
	ExitC        = make(chan bool)
	prefix       = "/ebike/config/manager"
)

type Config struct {
	Name    string `json:"name"`
	Env     string `json:"env"`
	Version string `json:"version"`

	HttpListen string `json:"http_listen"`
	Jaeger     string `json:"jaeger"`

	Collect struct {
		Log struct {
			FileName string `json:"file_name"`
			RedisKey string `json:"redis_key"`
		} `json:"log"`
		Trace struct {
			Addr string `json:"addr"`
		} `json:"trace"`
		Metric struct {
			Addr string `json:"addr"`
		} `json:"metric"`
	} `json:"collect"`

	DB []struct {
		Addr string `json:"addr"` // host=127.0.0.1 user=root password=root dbname=signal port=5432 sslmode=disable TimeZone=Asia/Shanghai
		Type string `json:"type"` // postgres, mysql, sqlite, mongo
		User string `json:"user"` // if addr not like Addr example or other need, you should set
		Pwd  string `json:"pwd"`
	} `json:"db"`

	Redis struct {
		Addr string `json:"addr"`
		Pwd  string `json:"pwd"`
	} `json:"redis"`

	Broker struct {
		Type string `json:"type"` // support: rabbitmq, nats
		Addr string `json:"addr"`
		User string `json:"user"`
		Pwd  string `json:"pwd"`
	} `json:"broker"`

	JwtToken struct {
		PrivateKey string `json:"private_key"`
		PublicKey  string `json:"public_key"`
	} `json:"jwt_token"`

	Traefik struct {
		EnableRouter bool   `json:"enable_router" yaml:"enable_router" toml:"enable_router"`
		Type         string `json:"type" yaml:"type", toml:"type"`
		// router rule  value: "||", "&&"
		Rule    string `json:"rule" yaml:"rule" yaml:"toml"`
		TLS     bool   `json:"tls" yaml:"tls" yaml:"tls"`
		Enabled bool   `json:"enabled" yaml:"enabled" toml:"enabled"`
		Domain  string `json:"domain" yaml:"domain" toml:"domain"`
		Prefix  string `json:"prefix" yaml:"prefix" toml:"prefix"`
	} `json:"traefik" yaml:"traefik" toml:"traefik"`

	// 绑定白名单
	BidingWhiteList []string `json:"biding_white_list" yaml:"biding_white_list" toml:"biding_white_list"`

	SystemSetting struct {
		HillAssist      int `json:"hill_assist"`
		HillAssistRange int `json:"hill_assist_range"`
		FlyCar          int `json:"fly_car"`
		Type            int `json:"type"`
		EbikeSet        struct {
			PowerWarn            int `json:"power_warn"`
			PowerValue           int `json:"power_value"`
			LeaveLock            int `json:"leave_lock"`
			OpenLock             int `json:"open_lock"`
			LeaveCountdown       int `json:"leave_countdown"`
			OpenLockDistance     int `json:"open_lock_distance"`
			HitchsUp             int `json:"hitchs_up"`
			Alarm                int `json:"alarm"`
			VibrationSensitivity int `json:"vibration_sensitivity"`
			ElectronicFence      int `json:"electronic_fence"`
			FenceCenter          struct {
				X float64 `json:"x"`
				Y float64 `json:"y"`
			} `json:"fence_center"`
			FenceRadius int `json:"fence_radius"`
		} `json:"ebike_set"`
		MsgSet struct {
			StealAlarm    int `json:"steal_alarm"`
			Hitchs        int `json:"hitchs"`
			Shake         int `json:"shake"`
			BlackOut      int `json:"black_out"`
			ChargeMonitor int `json:"charge_monitor"`
			Handrail      int `json:"handrail"`
		} `json:"msg_set"`
	} `json:"system_setting"`
}
